<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/base.js" type="text/javascript"></script>
</head>
<style>
    .mytable{border: 1px solid red; width: 400px;height:auto;}
    td{ background-image: linear-gradient(to right, red , yellow);background-color: red;}
</style>
<body>
    <h1 onclick="myfn()">对象</h1>

    <h1>函数</h1>
    <script>

        //数据存储 方法以及功能封装
        let person = {
            //property value
            name : "康",
            age : 38,
            sex :'man',
            hobby:[123,"str",null,undefined,[123]]
        };

        console.log(person,typeof person);


        //第一种
        function add(x,y){
            x = x | 0;
            y = y | 0;
            return x + y;
        }

        console.log(add(2));
        //第二种 匿名函数
        let add1 = function (){
            return 2 + 3;
        }

        console.log(add1(),typeof add1);

        //第三种 对大量的方法进行统一化封装
        let dog = {
            run : function (){
                return "狗跑的很快";
            },
            eat:function (){
                return "狗行千里吃肉";
            }
        }

        //第四种 lambda 短箭函数
        let add3 = (x,y) => x + y;

        console.log(dog,dog.eat(),add3(3,4));
   
        // 面向对象编程 
        // public class Person{
        //     public String info(){
        //         return "这是一个人";
        //     }
        // }
        function Person(){
            //里面的全局变量
            var a = 13;
            this.info = ()=>{
                let b = 14;
                return "这是一个人" + a;
            };
            this.abc=function (){
                
            }
        }


        let p1 = new Person();


        let json = {name:"abc",age:"23",sex:"男"}

        console.error( json);
        let stu = {code:200,msg:'success',data:[
            {sno:1,sname:"admin",sage:13},
            {sno:2,sname:"admin1",sage:13},
            {sno:3,sname:"admin2",sage:13},
            {sno:4,sname:"admin3",sage:13},
            {sno:5,sname:"admin4",sage:13},
        ]};

        if(stu != null && stu.code === 200){
            let arr = stu.data;
            document.write("<table class='mytable'>")
            document.write("<tr><th>序号</th><th>姓名</th><th>年龄</th></tr>")
            for(let i = 0;i < arr.length;i++){
                document.write("<tr>")
                document.write("<td>");
                document.write(arr[i].sno);
                document.write("</td>");
                document.write("<td>");
                document.write(arr[i].sname);
                document.write("</td>");
                document.write("<td>");
                document.write(arr[i].sage);
                document.write("</td>");
                document.write("</tr>");
            }
            document.write("</table>")
        }

        //JSON h5的浏览器内置的一个对象，用来完成json与字符串转换功能

        // JSON.stringify(stu) // 把json转换成为jsonstring
        // JSON.parse("{a:123}") //把json字符串转换成为object
        document.write(JSON.stringify(stu));

    </script>
</body>
</html>
